<template>
    <div class="dhzn_slideshow">

        <div v-for="(item,key) in slideshowlist" :key="key">
            <span>{{item.id}}</span>
            <img :src="item.imageurl">
            <span>{{item.goodsid}}</span>
        </div>

        <div class="dh_g-block mt20">
            <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="currentPage"
                :page-size="pagesize"
                layout="total, prev, pager, next, jumper"
                :total="total">
            </el-pagination>
        </div>

    </div>
</template>

<script>
const axios = require('axios')
export default {
    components: {},
    data() {
        return {
            token: '',
            slideshowlist: [],
            currentPage: 1,						//分页的默认页数
            pagesize: 10,                       //单页条数
            total: 0,                           //总数据条数
        };
    },
    computed: {},
    watch: {},
    methods: {
        
        // 单页条数
        handleSizeChange(val) {
            // console.log(`每页: ${val}条数据`);
            this.pagesize = val;
            // if(that.paging === 1){
            //     that.classifylatt()
            // }else if(that.paging === 2){
            //     that.lookson()
            // }else if(that.paging === 3){
            //     that.inquire()
            // }else{
            //     that.updataclassify()
            // }
        },

        //分页的跳页函数
        handleCurrentChange(val) {
            // console.log(`当前页: ${val}`);
            const that = this;
            that.currentPage = val;
            // if(that.paging === 1){
            //     that.classifylatt()
            // }else if(that.paging === 2){
            //     that.lookson()
            // }else if(that.paging === 3){
            //     that.inquire()
            // }else{
            //     that.updataclassify()
            // }
        },

        requestslideshow(){
            let that = this;
            let data = {current:that.currentPage,size:that.pagesize};
            let updata = JSON.stringify(data);
            axios({
                method: 'post',
                url: '/api/goodsBanner/list',
                headers: {
                    'Content-Type': 'application/json',
                    'authorization': `Bearer ${JSON.parse(sessionStorage.getItem('token'))}`,
                },
                data: updata
            })
            .then( resp=> {
                // console.log(resp)
                that.slideshowlist = resp.data.data;
                for(var i=0;i<that.slideshowlist.length;i++){
                    sessionStorage.removeItem("token")
                    location.reload()
                }
            })
        },

        //拿TOKEN
        newtoken(){
            let that = this;
            let axios = require('axios')
			let loguser = JSON.parse(sessionStorage.getItem('updata'))
			let data = {username:loguser.username, password:loguser.password};
			let updata = JSON.stringify(data);
			console.log(updata)
			axios({
				method: 'post',
				url: '/api/getAuthority/manager',
				headers: { 'Content-Type': 'application/json' },
				data: updata
			})
			.then( resp=> {
                that.token = resp.data.data;
				sessionStorage.setItem("token", JSON.stringify(resp.data.data))
                that.requestslideshow()
			}).catch( err=> {})
        }    
    },
    created() {},
    mounted() {
        let that = this;
        that.newtoken()
    },
    beforeCreate() {},
    beforeMount() {},
    beforeUpdate() {},
    updated() {},
    beforeDestroy() {},
    destroyed() {},
    activated() {},
    }
</script>
<style scoped>

</style>